var conn = require('./database.js');

module.exports = {
    find : function(id, callback) {
        var sql = "SELECT * FROM go_member WHERE id = ?";
        conn.getConnection(function (err, connection) {
            if (err) {
                callback(true, err);
                return;
            }   
            connection.query(sql, [id], function (err, results) {
                if (err) {
                    callback(true, err);
                    return;
                }
                connection.release();
                callback(false, results[0]);
            });
        });
    },
    select : function (where, callback) {
        var sql = "SELECT * FROM go_member";
        conn.getConnection(function (err, connection) {
            if (err) {
                callback(true, err);
                return;
            }
            connection.query(sql, function (err, results) {
                if (err) {
                    callback(true, err);
                    return;
                }
                connection.release();
                callback(false, results);
            });
        });
    },
    query : function (sql, callback) {
        conn.getConnection(function (err, connection) {
            if (err) {
                callback(20001, err.errno);
                return;
            }
            connection.query(sql, function (err, results) {
                if (err) {
                    callback(true, err);
                    return;
                }
                connection.release();
                callback(false, results);
            });
        });
    }
}